package graphAlg.gen;

import graphAlg.Graph;
import graphAlg.GraphGenerator;
import graphAlg.Node;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

public class Graph_BFS {
    public static void main(String[] args) {
        Graph graph = GraphGenerator.createGenerateGraph(new int[][]{
                {1, 2, 3},
                {1, 3, 4},
                {1, 4, 5},
                {2, 3, 6},
                {3, 4, 7},
                {2, 5, 8},
                {3, 5, 9},
                {4, 6, 10},
                {6, 7, 11}
        });
        bfs(graph.getNodes().get(1));

    }

    public static void bfs(Node node) {
        Queue<Node> queue = new LinkedList<>();
        Set<Node> set = new HashSet<>();
        queue.add(node);
        set.add(node);
        while(!queue.isEmpty()){
            Node curNode = queue.poll();
            System.out.print(curNode + " ");
            for(Node nextNode : curNode.nexts){
                if(!set.contains(nextNode)){
                    queue.add(nextNode);
                    set.add(nextNode);
                }
            }


        }
    }
}
